﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>人员设置</title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/setPeople.js"></script>
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<script type="text/javascript" src="../js/gbRst.js"></script>
<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script>
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<link href="../css/validator3.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/ajaxfileupload.js"></script> 
<script type="text/javascript" src="../js/ImageBrowsing.js"></script> 
<script charset="utf-8" src="../js/kindeditor.js"></script>
<script charset="utf-8" src="../js/lang/zh_CN.js"></script>
<script type="text/javascript" src="../js/editor.js"></script>    
<script type="text/javascript" src="../js/find.js"></script>   
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<style type="text/css">

</style>
<script type="text/javascript" >
function bclicks(obj){
	var $first=obj.parent("td").parent("tr").children("td:first");
	var id=$first.html();
	var name=$first.next().html();
	//$("#shopName").children("option").blur();
	getParamToshopS(id,name)
}
var pagecount = 0;
var count = 0;
var shopId="shopId";
var shopPageCount=0;
var shopCount=0;
var mainShopId=0;
var pageIndex=1;

$(function(){
	refreshInput($(".serWrapper"));
	$("#shopIsChoosed").click(function(){
		if($("#shopIsChoosed").is(":checked")){
			$("#shopName").attr("disabled",false);
		}else{
			$("#shopName").attr("disabled",true);

		}
	})
	addMargin($("#window_change"));
	addMargin($("#Postset"));
	addMargin($("#personShop"));
	addMargin($("#personPost"));
	$("#shopName2").click(function(){
		$(this).blur();
		$("#personShop,#yinyingCenter").show();
	})
	
	$("#onlyPost").click(function(){
		$("#personPost,#yinyingCenter").show();
	})
	

	browse('upload','imgSrc',100,100);


}); 


function shopExits(id){
	var bloo=false
	$("#shopName").find("option").each(function(){
		
		if($(this).attr("value")===id){
			bloo= true;
			return bloo;
		}
	})
	return bloo;
}
function getParamToshopS(id,name){
	var shopflag=$("#shopflag").val();
	if(shopflag==1){
	var htm="<option value='"+id+"'>"+name+"</option>"
	$("#shopName").html(htm);
	$("#shopName").val(id);
	}else if(shopflag==2){
		var flag=false;
		$("#ownShopList tbody tr").each(function(){
			var shopId=$(this).find("td:first").html();
			if(shopId==id){
				flag=true;
			}
		})
		if(flag){
			art.dialog({fixed:true, lock: true,content:"已选择该店铺",icon:'error',ok:true});	
			return false;
		}
		$("#ownShopList tbody").append("<tr></tr>");
		var htm;
		var doflag=$("#doflag").val()
			
		if(doflag==1){
		if(userType==0){
			var count=$("#ownShopList tbody tr").length;
			if(count==1){
			 htm="<td>"+id+"</td><td>"+name+"</td><td><input class='mainShop'  onclick='chooseMainShopId( $(this),"+id+")' class=\"del\" type=\"button\" value=\"所属\"><input onclick='deleteOwnShop($(this),"+id+")' class=\"del\" type=\"button\" value=\"删除\"></td>"
				mainShopId=id;
			}else{
				 htm="<td>"+id+"</td><td>"+name+"</td><td><input class='notMainShop'  onclick='chooseMainShopId( $(this),"+id+")' class=\"del\" type=\"button\" value=\"所属\"><input onclick='deleteOwnShop($(this),"+id+")' class=\"del\" type=\"button\" value=\"删除\"></td>"	
			}
		}else{
		htm="<td>"+id+"</td><td>"+name+"</td><td><input onclick='deleteOwnShop($(this),"+id+")' class=\"del\" type=\"button\" value=\"删除\"></td>"
		}
		}else if(doflag==2){
		htm="<td>"+id+"</td><td>"+name+"</td><td><input onclick='deleteOwnShop($(this),"+id+")' class=\"del\" type=\"button\" value=\"删除\"></td>"
	
		}
		$("#ownShopList tbody tr:last").append(htm)
		addMargin($("#personShop"))

	}
	closeShopShow();
}

function chooseMainShopId(obj,id){
	$("#ownShopList tbody tr").each(function(){
		$(this).find("input:first").removeClass("mainShop").addClass("notMainShop");
	})
	obj.removeClass("notMainShop").addClass("mainShop");
	mainShopId=id;
}

function closeShopShow(){
	$("#shopShow,#yinying").hide();
	$("#searchName").val("")
}

function InitShopList(shopPageIndex){
	var shopName=$("#searchName").val();
	$.ajax({
		type : "post",
		async:false,
		data :'name='+shopName,
		datatype : "json",
		url : "../shop/find/shopList/" + shopPageIndex + "/5",
		success : function(data) {
			var rst = JSON.parse(data);
			if(IsEmpty(rst)){
				art.dialog({fixed:true, lock: true,content:"查询出错",icon:'error',ok:true});	
				return false;
				}
				if(rst.state==0){
					$("#shopList tbody tr").remove();

					initShopTable(rst);
					$("table[id='shopList'] tbody tr").each(function(){
						$(this).children("td:last").css("text-align","center").append("<input type='button' class='common_btn' value='选择' onclick='bclicks($(this))'>");

					})	
					if(rst.result.len > 0){
						 var shu = rst.result.len;
						 shopCount = Math.ceil(shu/5);					
						 }else{
								shopCount==0;
						 }
					 $("#shopPager").pager({ pagenumber: ++shopPageIndex, pagecount: shopCount, buttonClickCallback: ShopPageClick });
					 addMargin($("#shopShow"));	
					 }else if(rst.state==1){
					art.dialog({fixed:true, lock: true,content:rst.msg,icon:'error',ok:true});	
				}else{
					checkStateShowErrorMsgAndDealResult(data);
				}
		}	
	});
}
// ===========7897897===========
// 	"find/dutyList/{pageIndex}/{pageSize}"
function InitPostList(){
	if(toOwnShopIds.length==0){
		art.dialog({fixed:true, lock: true,content:"请先选择店铺",icon:'error',ok:true});	

		return false;
	}
	$.ajax({
		type : "get",
		async:false,
		datatype : "json",
		url : "../duty/find/canOwnDuty",
		data:"ids="+toOwnShopIds,
		success : function(data) {
			var rst = JSON.parse(data);
			if(IsEmpty(rst)){
				art.dialog({fixed:true, lock: true,content:"查询出错",icon:'error',ok:true});	
				return false;
				}
				if(rst.state==0){
					if(rst.result.len==0){
						art.dialog({fixed:true, lock: true,content:"你选择的店铺暂无岗位,请先添加对应店铺岗位",icon:'error',ok:true});	
						return false;
					}
					$("#postList tbody").empty();
					for ( var i = 0; i < rst.result.len; i++) {
					$("#postList tbody").append("<tr></tr>");
					var id=getHeadIndexValue(i, rst, "id");
					var shopName=getHeadIndexValue(i, rst, "ShopName");
					var shopId=getHeadIndexValue(i, rst, "ShopId");
					var code=getHeadIndexValue(i, rst, "Code");
					var name=getHeadIndexValue(i, rst, "Name");
					var htm="<td>"+shopName+"</td><td>"+code+"</td><td>"+name+"</td><td><input onclick='choosePost("+id+","+shopId+",$(this))' class=\"common_btn\" type=\"button\" value=\"选择\"></td>"
					$("#postList tbody tr:last").append(htm);

					}
					
					addMargin($("#Postset"))
					 }else if(rst.state==1){
					art.dialog({fixed:true, lock: true,content:rst.msg,icon:'error',ok:true});	
				}else{
					checkStateShowErrorMsgAndDealResult(data);
				}		
		}	
	});
}

function choosePost(id,shopId,obj){
	var flag=false;
	$("#ownPostList tbody tr").each(function(){
		var codeid=$(this).find("td:first").find("input").val();
		if(id==codeid){
			flag=true;
			
		}
	})
	if(flag){
		art.dialog({fixed:true, lock: true,content:"您已选择该岗位",icon:'error',ok:true});	

		return false;
	}
	
	var shopName=obj.parents("tr").find("td").eq(0).html();
	var code=obj.parents("tr").find("td").eq(1).html();
	var postName=obj.parents("tr").find("td").eq(2).html();
	$("#ownPostList tbody").append("<tr></tr>");
	var htm="<td><input type='hidden' value='"+id+"'> <input type='hidden' value='"+shopId+"'>  "+shopName+"</td><td>"+code +"</td><td>"+postName+"</td><td><input class=\"del\" onclick=' deleteOwnPost($(this))' type=\"button\" value=\"删除\"></td>"
	$("#ownPostList tbody tr:last").append(htm);
	$("#Postset,#yinying").hide()
}


function InitTable() {
	var phone=$("#phone").val().replace(/\s/gi,'');	
	var status=$("#status").val();
	var username=$("#username").val();
	var loginname=$("#loginname").val();
	var shopId="";
	var param='phone='+phone+"&status="+status+"&username="+username+"&loginname="+loginname;
	if($("#shopIsChoosed").is(":checked")){
		shopId=$("#shopName").val();		
		if(shopId!=""&&shopId!=null){
			param+="&shopId="+shopId;
		}
	}
//      if()
	$.ajax({
		type : "post",
		async:false,
		data :{'phone':phone,'status':status,'username':username,'loginname':loginname,'shopId':shopId},
		datatype : "json",
		url : "../user/find/userList/" + pageIndex + "/10",
		success : function(data) {
			var rst = JSON.parse(data);
						
					
					if(IsEmpty(rst)){
						art.dialog({fixed:true, lock: true,content:"查询出错",icon:'error',ok:true});	
						return false;
						}
						if(rst.state==0){
							$("#memberList tbody tr").remove();
							var obj = DealAndShowMsg(data,false,false);
							initTable(rst);	
							if(rst.result.len > 0){
								 var shu = rst.result.len;
							 	 pagecount = Math.ceil(shu/10);
							 	 $("#NoResult").hide();
							}else{
								$("#NoResult").show();
								pagecount=0;

							}
							 	$("#sup").html("共"+rst.result.len+"条");	
							 	$("#pager").pager({ pagenumber: pageIndex, pagecount: pagecount, buttonClickCallback: PageClick });
							
							 }else if(rst.state==1){
							art.dialog({fixed:true, lock: true,content:rst.msg,icon:'error',ok:true});	
						}else{
							checkStateShowErrorMsgAndDealResult(data);
						}				
		}	
	});
}

ShopPageClick = function(pageclickednumber) {
    $("#shopPager").pager({ pagenumber: --pageclickednumber, pagecount: pagecount, buttonClickCallback: PageClick });
    $("#result").html("Clicked Page " + pageclickednumber);
    InitShopList(pageclickednumber);
}

PageClick = function(pageclickednumber) {
   	pageIndex=pageclickednumber;
	InitTable();
}

function search(){
	InitTable();
}
function search2(){
	InitShopList(0);
}
function initTable(json){
	
	$("#memberList tbody").empty();
	for ( var i = 0; i < json.result.data.length; i++) {
		var htm="<tr>"
			htm+="<td><img src='"+ _getStringOfJson(i, json, "imageUrl")+"'/></td>"
			htm+="<td>"+_getStringOfJson(i, json, "Name")+"</td>"
			htm+="<td>"+_getStringOfJson(i, json, "LoginName")+"</td>"
			htm+="<td>"+_getStringOfJson(i, json, "Sex")+"</td>"
			htm+="<td>"+_getStringOfJson(i, json, "IDNumber")+"</td>"
			htm+="<td>"+_getStringOfJson(i, json, "Address")+"</td>"
			htm+="<td>"+_getStringOfJson(i, json, "Tel")+"</td>"
			htm+="<td>"+_getStringOfJson(i, json, "Mp")+"</td>"
			htm+="<td>"+_getStringOfJson(i, json, "Email")+"</td>"
			htm+="<td>"+_getStringOfJson(i, json, "duty")+"</td>"
			htm+="<td>"+_getStringOfJson(i, json, "StatusName")+"</td>"
			htm+="<td>"+_getStringOfJson(i, json, "CreateFileTime")+"</td>"
			var id = _getIntOfJson(i, json, "ID")
			htm+="<td><input class=\"common_btn \" type=\"button\" value=\"修改\"  onclick=\"showEditPersonnel("+id+")\"><input class=\"del\" type=\"button\" onclick=\"popPoint("+id+")\" value=\"删除\"></td>"
			htm+="</tr>"
				$("#memberList tbody").append(htm)
	}

}



function initShopTable(json){
	if(json!=null && json.state==0){
		var params = new Array("id", "name","mp","contact");
		Loadtable(json,params,"shopList");
	}
}
function initPostTable(json){
	if(json!=null && json.state==0){
// 		{"msg":"","state":0,"result":{"len":15,"head":["ShopName","id","Code","Name","ShopId"],"data":[["圣草实友会总部店",44,"E12","Ce",280000022],[null,43,"12","售后",null],[null,42,"11","销售员",null],[null,41,"11","董事长",null],[null,37,"7","系统管理员",null]]}}
		var params = new Array("ShopName", "Code","Name","contact");
		Loadtable(json,params,"PostList");
	}
}


function Loadtable(json, params, tableId,custmID){
	var phArray = new Array();
	var count = 0;
	var custmIDCount = 0;
	if (params != null) {
		$(params).each(function(pIndex, pData) {
			$.each(json.result.head, function(hIndex, hData) {
				if (pData == hData) {
					phArray[count++] = hIndex;
				}
			});
		});
	}
	 if(custmID==null){
		 custmID="";
	    }
	var custmIDArr = new Array(custmID.length);
	$(custmID).each(function(index, ffData) {
		$.each(json.result.head, function(ffIndex, fffData) {
			if (fffData == ffData) {
				custmIDArr[custmIDCount++] = ffIndex;
			}
		});
	});
	if (json.result.data != null) {
		$.each(json.result.data, function(index, dt) {
			$("table[id='" + tableId + "']").append("<tr></tr>");
			$(phArray).each(function(phIndex, data) {
				$.each($(dt), function(dtIndex, d) {
					if (dtIndex == data) {
						if (isHiddenFile(custmIDArr,data)){
// 							<input type="button" class="common_btn" value="修改">
// 				            <input type="button" class="del common_btn" value="删除"></td>
						    $("table[id='"+ tableId+ "'] tr:last").append("<td><input type='button' name='"+d+"' class='common_btn' onclick='showEditPersonnel(this.name)' value='修改'><input type='button' name='"+d+"' class='del common_btn' onclick='popPoint(this.name)' value='删除'></td>");
							}else{
							$("table[id='" + tableId + "'] tr:last").append("<td>" +  (d === null||d == "null" ? " " : d) + "</td>");
							}
					}
				});
			});
		});
	}
}

function popPoint(id){
	art.dialog({fixed:true, lock: true,content:"确认删除该条数据？",icon:'question',ok: function(){ deletePersonnel(id)},cancel:true});
	}
function  deletePersonnel(id){
	  var url=" ../user/del";
	  
	  var dt = _deleteInfo(url, {"id":id});
	  if(dt.state==0){
			search();
	  }

	}
	

function getOwnShop(id){
	$.ajax({
		type : "get",
		async:false,
		datatype : "json",
		url : "../shopUser/find/userId/all/"+id,
		success : function(data) {
			var rst = JSON.parse(data);
			if(IsEmpty(rst)){
				art.dialog({fixed:true, lock: true,content:"查询出错",icon:'error',ok:true});	
				return false;
				}
				if(rst.state==0){
					ownShopIds=new Array();
					toOwnShopIds = new Array();
					$("#ownShopList tbody").empty();

					for ( var i = 0; i < rst.result.len; i++) {
						var shopId= getHeadIndexValue(i, rst, "ShopID");
						ownShopIds.push(shopId);
						toOwnShopIds.push(shopId)
						var shopName=getHtmlString(getHeadIndexValue(i, rst, "ShopName"));
					
						$("#ownShopList tbody").append("<tr></tr>");
						var htm=null;
						if(getHeadIndexValue(i, rst, "Default")){
						mainShopId=shopId	
						htm="<td>"+shopId+"</td><td>"+shopName+"</td><td><input class=\"del\" type=\"button\" value=\"所属店铺不可删除\"></td>"
						}else{
						htm="<td>"+shopId+"</td><td>"+shopName+"</td><td><input onclick='deleteOwnShop($(this),"+shopId+")' class=\"del\" type=\"button\" value=\"删除\"></td>"
							
						}
						$("#ownShopList tbody tr:last").append(htm)

					}
					saveOwnShopIds();
					addMargin($("#personShop"))
					 }else if(rst.state==1){
					art.dialog({fixed:true, lock: true,content:rst.msg,icon:'error',ok:true});	
				}else{
					checkStateShowErrorMsgAndDealResult(data);
				}
			
			
		}	
	});
}

function getOwnPost(userid){
	$.ajax({
		type : "get",
		async:false,
		datatype : "json",
		url : "../userDuty/find/userId/"+userid,
		success : function(data) {
			var rst = JSON.parse(data);
			if(IsEmpty(rst)){
				art.dialog({fixed:true, lock: true,content:"查询出错",icon:'error',ok:true});	
				return false;
				}
				if(rst.state==0){
					ownPostIds=new Array();
					toOwnPostIds=new Array();
					$("#ownPostList tbody").empty();
					for ( var i = 0; i < rst.result.len; i++) {
						var shopName=getHtmlString(getHeadIndexValue(i, rst, "shopName"));
						var code=getHtmlString(getHeadIndexValue(i, rst, "dutyCode"));
						var postName=getHtmlString(getHeadIndexValue(i, rst, "dutyName"));
						var shopId=getHtmlInt(getHeadIndexValue(i, rst, "shopId"));
						var id=getHtmlInt(getHeadIndexValue(i, rst, "dutyId"));
						ownPostIds.push(id);
						toOwnPostIds.push(id);
						$("#ownPostList tbody").append("<tr></tr>");
						var htm="<td><input type='hidden' value='"+id+"'> <input type='hidden' value='"+shopId+"'>  "+shopName+"</td><td>"+code+"</td><td>"+postName+"</td><td><input class=\"del\" onclick=' deleteOwnPost($(this))' type=\"button\" value=\"删除\"></td>"
						$("#ownPostList tbody tr:last").append(htm);
					}
					
					addMargin($("#personShop"))

					saveOwnPostIds();
					 }else if(rst.state==1){
					art.dialog({fixed:true, lock: true,content:rst.msg,icon:'error',ok:true});	
				}else{
					checkStateShowErrorMsgAndDealResult(data);
				}	
			
			
		}	
	});
}

function deleteOwnShop(obj,shopId){
	var flag=false;
	$("#ownPostList tbody tr").each(function(){
		var postShopId=$(this).find("td:first").find("input").next().val();
		if(shopId==postShopId){
			flag=true;
		}
	})
	
	var count =	$("#ownShopList tbody tr").length
	if(count>1){		
	if(mainShopId==shopId){
		art.dialog({fixed:true, lock: true,content:"所属店面不可删除,请先更改所属店,在删除该店面!，",icon:'error',ok:true})
		return false;	
	}
	}
	
	
	if(flag){
		
		art.dialog({fixed:true, lock: true,content:"删除该店铺将删除在该店铺中岗位，是否继续删除?",icon:'question',ok:function(){
			$("#ownPostList tbody tr").each(function(){
				var postShopId=$(this).find("td:first").find("input").next().val();
				if(shopId==postShopId){
					$(this).remove()
				}
			})
			obj.parents("tr").remove();
			addMargin($("#personShop"))
			saveOwnPostIdsBydelete()
			
		},cancel:true});
	}else{
		obj.parents("tr").remove();
		addMargin($("#personShop"))
		saveOwnPostIdsBydelete()
	}
	
	
	

}
function deleteOwnPost(obj){
	obj.parents("tr").remove();
	addMargin($("#personShop"))
	saveOwnPostIdsBydelete()
}
//===========编辑的部分===============
function showEditPersonnel(id){    //  编辑人员信息
	$("#doflag").val(2);
	$("#updateId").val(id);
	  var url=" ../user/find/userById";
	  if(id>0){
		$.get(url,{"id":id},function(g){
			var rst = JSON.parse(g);
			$("#shopName2").html($("#shopName").html());//将页面的值赋给弹出层
			
			$("#Name").val(_getStringOfJson(0, rst, "Name")); 
			$("#LoginName2").val(_getStringOfJson(0, rst, "LoginName"));
			$("#password").val(_getStringOfJson(0, rst, "passWord"))
            var htm="";
			if(_getStringOfJson(0, rst, "Status")==0){
			 htm="<option value='0'>正常</option><option value='1'>停用</option>"
			}else{
			 htm="<option value='1'>停用</option><option value='1'>正常</option>"
			} 
			$("#Status").html(htm); 
			if(_getStringOfJson(0, rst, "Sex")=="男"){
			 htm="<option value='1'>男</option><option value='0'>女</option>"
			}else{
			 htm="<option value='0'>女</option><option value='1'>男</option>" 
			}
			$("#Sex").html(htm); 
			$("#IDNumber").val(_getStringOfJson(0, rst, "IDNumber")); 
			$("#Address").val(_getStringOfJson(0, rst, "Address")); 
			$("#Tel").val(_getStringOfJson(0, rst, "Tel")); 
			$("#Mp").val(_getStringOfJson(0, rst, "Mp")); 
			$("#Email").val(_getStringOfJson(0, rst, "Email")); 
			$("#ZipCode").val(_getStringOfJson(0, rst, "ZipCode")); 
			$("#DeptName").val(_getStringOfJson(0, rst, "DeptName"));
			$("#imgSrc img").attr("src",_getStringOfJson(0, rst, "imageUrl"))
			$("#indexUrl").val(_getStringOfJson(0, rst, "indexUrl"))
			$("#imageUrl").val(_getStringOfJson(0, rst, "imageUrl"))
			getOwnShop(id);
			getOwnPost(id);
			if(_getIntOfJson(0, rst, "isHost")==1){
				$("#isHost").attr("checked",true)
			}
			var dt = _findInfo("../htmlUtils/find/shophtmlStr/"+id+"/user", null)
			if(dt.state==0){
				editorHtml = _getStringOfJson(0, dt, "htmlStr");
			}
			
			
			$("#yinying1,#window_change").show();	
			addMargin($("#Postset"));
			
		});
	  }
	  
}

function showShopList(a){
	$("#shopflag").val(a);
	$("#shopName,#shopName2").blur();
	$("#shopShow,#yinying").show();
	InitShopList(0);
}

function  downRescouse(){
	var phone=$("#phone").val().replace(/\s/gi,'');	
	var status=$("#status").val();
	var shopId="";
	var param='phone='+phone+"&status="+status;
	if($("#shopIsChoosed").is(":checked")){

		
		shopId=$("#shopName").val();
		
		if(shopId!=""&&shopId!=null){
			param+="&shopId="+shopId;
		}
	}
	param+="&downType=7"
	window.location.href="../csvdown/down/csv/down?"+param
}
function showPost(){
	
	$("#Postset,#yinying").show();
	InitPostList();
}
function save(){
	var doflag=$("#doflag").val();
	if(doflag==1){
		addInfo();
		
	}else if(doflag==2){
		updateInfo();
	}else{
		art.dialog({fixed:true, lock: true,content:"页面出错",icon:'error',ok:true});	

		window.location.reload();
	}
}

 function addInfo(){
		
	 var loginName=$("#LoginName2").val();
	 var Status2=$("#Status2").val();
	 var Sex=$("#Sex").val();
	 var IDNumber=$("#IDNumber").val();
	 var Address=$("#Address").val();
	 var Tel=$("#Tel").val();
	 var Mp=$("#Mp").val();
	 var Email=$("#Email").val();
	 var ZipCode=$("#ZipCode").val();
	 var Name=$("#Name").val();
	 var password=$("#password").val();
		
	 
	 if(IsEmpty(loginName)){
			art.dialog({fixed:true, lock: true,content:"请输入登录名",icon:'error',ok:true});
			$("#LoginName2").focus();
			return false;
	 }else{
		 if(loginName.length>50){
			 art.dialog({fixed:true, lock: true,content:"登录名过长(50字以内)",icon:'error',ok:true});
				$("#LoginName2").focus();
				return false;
		 }
	 }
	 if(IsEmpty(password)){
		 	art.dialog({fixed:true, lock: true,content:"请输入密码",icon:'error',ok:true});
			$("#password").focus();
			return false;
	 }else{
		 if(password.length>20){
			 art.dialog({fixed:true, lock: true,content:"密码过长(20字以内)",icon:'error',ok:true});
				$("#password").focus();
				//return false;
		 }
	 }
	 if(IsEmpty(Name)){
		 art.dialog({fixed:true, lock: true,content:"请输入姓名",icon:'error',ok:true});
			$("#Name").focus();
			return false;	
	}else{
		if(Name.length>20){
			 art.dialog({fixed:true, lock: true,content:"姓名过长(20字以内)",icon:'error',ok:true});
				$("#Name").focus();
				return false;	
		}
	}
	 
	 if(toOwnShopIds.length==0){
			art.dialog({fixed:true, lock: true,content:"请选择店铺",icon:'error',ok:true});	
			return false;
		}
	 if(toOwnPostIds.length==0){
			art.dialog({fixed:true, lock: true,content:"请选择岗位",icon:'error',ok:true});	
			return false;
		}
	 if(IsNotEmpty(ZipCode)){
		 var exp = /\d{6}$/;
		    if(!exp.test(ZipCode)){
			art.dialog({fixed:true, lock: true,content:'邮编格式错误',icon:'error',ok:true});
			$("#ZipCode").focus();
			return false;
		    }	 
		}
	 if(IsNotEmpty(Email)){
		 var exp = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
		    if(!exp.test(Email)){
			art.dialog({fixed:true, lock: true,content:'邮箱格式错误',icon:'error',ok:true});
			$("#Email").focus();
			return false;
		    }	 
		}else{
			if(Email.length>50){
				art.dialog({fixed:true, lock: true,content:'邮箱过长(50字以内)',icon:'error',ok:true});
				$("#Email").focus();
				return false;
			}
		}
	 if(IsNotEmpty(Mp)){
		 var exp = /(13|15|18)[0-9]{9}$/;
		    if(!exp.test(Mp)){
			art.dialog({fixed:true, lock: true,content:'手机格式错误',icon:'error',ok:true});
			$("#Mp").focus();
			return false;
		    }	 
		}
	 if(IsNotEmpty(IDNumber)){
		 var exp = /^[1-9]([0-9]{14}|[0-9]{17})$/;
		    if(!exp.test(IDNumber)){
			art.dialog({fixed:true, lock: true,content:'身份证格式错误',icon:'error',ok:true});
			$("#IDNumber").focus();
			return false;
		    }	 
		}
	 
	 var isHost = 0;
	 if($("#isHost").is(":checked")){
		 isHost = 1;
	 }
	 var heads=new Array("name","sex","IdNumber","tel","mp","mail","address","loginName","status","zipCode","password","isHost");
		var datas=new Array(Name,Sex,IDNumber,Tel,Mp,Email,Address,loginName,Status2,ZipCode,password,isHost);
		var parser = new Object();
		var jsonParserStr = null;
		if (IsNotEmpty(datas)){
			addToParser(heads, datas, "add" , parser);
			jsonParserStr =  JSON.stringify(parser);
		}
		var parser2 = new Object();
		var jsonParserStr2 = null;
		
		for ( var i = 0; i < toOwnShopIds.length; i++) {
			 var heads=new Array("ShopID","Default");
			 if(toOwnShopIds[i]==mainShopId){
				 
			 var datas=new Array(toOwnShopIds[i],1);
			 }else{
				 var datas=new Array(toOwnShopIds[i],null);
	 
			 }
				if (IsNotEmpty(datas)){
					addToParser(heads, datas, "add" , parser2);
					jsonParserStr2 =  JSON.stringify(parser2);
				}
		}	
		
		var parser3 = new Object();
		var jsonParserStr3 = null;
		
		for ( var i = 0; i < toOwnPostIds.length; i++) {
			 var heads=new Array("dutyId");
				 
			 var datas=new Array(toOwnPostIds[i]);
			
				if (IsNotEmpty(datas)){
					addToParser(heads, datas, "add" , parser3);
					jsonParserStr3 =  JSON.stringify(parser3);
				}
		}
	$("#close_this").attr("disabled",true);	
	 $.post("../user/insert/insertInfo",{"data":jsonParserStr,"shopList":jsonParserStr2,"postDate":jsonParserStr3,"html":editorHtml}, function(data) {
			$("#close_this").attr("disabled",false);	
			var dt = JSON.parse(data);
			if(IsEmpty(dt)){
				art.dialog({fixed:true, lock: true,content:"添加出错",icon:'error',ok:true});	
				return false;
				}
				if(dt.state==0){
					upload(_getIntOfJson(0, dt, "id"));
					 }else if(dt.state==1){
					art.dialog({fixed:true, lock: true,content:dt.msg,icon:'error',ok:true});	
				}else{
					checkStateShowErrorMsgAndDealResult(data);
				}	
			
		});
 }
 
 function updateInfo (){

	 var id=$("#updateId").val();
	 var loginName=$("#LoginName2").val();
	 var Status2=$("#Status2").val();
	 var Sex=$("#Sex").val();
	 var IDNumber=$("#IDNumber").val();
	 var Address=$("#Address").val();
	 var Tel=$("#Tel").val();
	 var Mp=$("#Mp").val();
	 var Email=$("#Email").val();
	 var ZipCode=$("#ZipCode").val();
	 var Name=$("#Name").val();
	 var password=$("#password").val();
	
	 if(IsEmpty(loginName)){
			art.dialog({fixed:true, lock: true,content:"请输入登录名",icon:'error',ok:true});
			$("#LoginName2").focus();
			return false;
	 }else{
		 if(loginName.length>50){
			 art.dialog({fixed:true, lock: true,content:"登录名过长(50字以内)",icon:'error',ok:true});
				$("#LoginName2").focus();
				return false;
		 }
	 }
	 if(IsEmpty(password)){
		 	art.dialog({fixed:true, lock: true,content:"请输入密码",icon:'error',ok:true});
			$("#password").focus();
			return false;
	 }else{
		 if(password.length>20){
			 art.dialog({fixed:true, lock: true,content:"密码过长(20字以内)",icon:'error',ok:true});
				$("#password").focus();
				return false;
		 }
	 }
	 if(IsEmpty(Name)){
		 art.dialog({fixed:true, lock: true,content:"请输入姓名",icon:'error',ok:true});
			$("#Name").focus();
			return false;	
	}else{
		if(Name.length>20){
			 art.dialog({fixed:true, lock: true,content:"姓名过长(20字以内)",icon:'error',ok:true});
				$("#Name").focus();
				return false;	
		}
	}
	 
	 if(toOwnShopIds.length==0){
			art.dialog({fixed:true, lock: true,content:"请选择店铺",icon:'error',ok:true});	
			return false;
		}
	 if(toOwnPostIds.length==0){
			art.dialog({fixed:true, lock: true,content:"请选择岗位",icon:'error',ok:true});	
			return false;
		}
	 if(IsNotEmpty(ZipCode)){
		 var exp = /\d{6}$/;
		    if(!exp.test(ZipCode)){
			art.dialog({fixed:true, lock: true,content:'邮编格式错误',icon:'error',ok:true});
			$("#ZipCode").focus();
			return false;
		    }	 
		}
	 if(IsNotEmpty(Email)){
		 var exp = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
		    if(!exp.test(Email)){
			art.dialog({fixed:true, lock: true,content:'邮箱格式错误',icon:'error',ok:true});
			$("#Email").focus();
			return false;
		    }	 
		}else{
			if(Email.length>50){
				art.dialog({fixed:true, lock: true,content:'邮箱过长(50字以内)',icon:'error',ok:true});
				$("#Email").focus();
				return false;
			}
		}
	 if(IsNotEmpty(Mp)){
		 var exp = /(13|15|18)[0-9]{9}$/;
		    if(!exp.test(Mp)){
			art.dialog({fixed:true, lock: true,content:'手机格式错误',icon:'error',ok:true});
			$("#Mp").focus();
			return false;
		    }	 
		}
	 if(IsNotEmpty(IDNumber)){
		 var exp = /^[1-9]([0-9]{14}|[0-9]{17})$/;
		    if(!exp.test(IDNumber)){
			art.dialog({fixed:true, lock: true,content:'身份证格式错误',icon:'error',ok:true});
			$("#IDNumber").focus();
			return false;
		    }	 
		}
	 var isHost = 0;
	 if($("#isHost").is(":checked")){
		 isHost = 1;
	 }
	 var heads=new Array("isHost","name","sex","IdNumber","tel","mp","mail","address","loginName","status","zipCode","password","id");
		var datas=new Array(isHost,Name,Sex,IDNumber,Tel,Mp,Email,Address,loginName,Status2,ZipCode,password,id);
		var parser = new Object();
		var jsonParserStr = null;
		if (IsNotEmpty(datas)){
			addToParser(heads, datas, "edit" , parser);
			jsonParserStr =  JSON.stringify(parser);
		}
		
		
		var parser2 = new Object();
		var jsonParserStr2 = null;
		//判断新添加店铺
		for ( var i = 0; i < toOwnShopIds.length; i++) {
			var shopAddFlag=true;
			for ( var j = 0; j < ownShopIds.length; j++) {
				if(toOwnShopIds[i]==ownShopIds[j]){
					shopAddFlag=false;
				}	
			}
			if(shopAddFlag){
				 var heads=new Array("ShopID","Default","CustId");
				 if(toOwnShopIds[i]==mainShopId){
					 
				 var datas=new Array(toOwnShopIds[i],1,id);
				 }else{
					 var datas=new Array(toOwnShopIds[i],null,id);
		 
				 }
					if (IsNotEmpty(datas)){
						addToParser(heads, datas, "add" , parser2);
						jsonParserStr2 =  JSON.stringify(parser2);
					}	
			}
			
		}
		//判断删除的店铺
		for ( var i = 0; i < ownShopIds.length; i++) {
			var shopDeleteFlag=true;
			for ( var j = 0; j < toOwnShopIds.length; j++) {
				if(toOwnShopIds[j]==ownShopIds[i]){
					shopDeleteFlag=false;
				}	
			}
			if(shopDeleteFlag){
				 var heads=new Array("ShopID","CustId");
				 var datas=new Array(ownShopIds[i],id);

					if (IsNotEmpty(datas)){
						addToParser(heads, datas, "del" , parser2);
						jsonParserStr2 =  JSON.stringify(parser2);
					}	
			}
			
		}
		
		
		
		var parser3 = new Object();
		var jsonParserStr3 = null;
		//判断新添加岗位
		for ( var i = 0; i < toOwnPostIds.length; i++) {
			var postAddFlag=true;
			for ( var j = 0; j < ownPostIds.length; j++) {
				if(toOwnPostIds[i]==ownPostIds[j]){
					postAddFlag=false;
				}	
			}
			if(postAddFlag){
				 var heads=new Array("dutyId","custId");
				 var datas=new Array(toOwnPostIds[i],id);
					if (IsNotEmpty(datas)){
						addToParser(heads, datas, "add" , parser3);
						jsonParserStr3 =  JSON.stringify(parser3);
					}	
			}
			
		}
		//判断删除的岗位		
		for ( var i = 0; i < ownPostIds.length; i++) {
			var postDeleteFlag=true;
			for ( var j = 0; j < toOwnPostIds.length; j++) {
				if(toOwnPostIds[j]==ownPostIds[i]){
					postDeleteFlag=false;
				}	
			}
			if(postDeleteFlag){
				var heads=new Array("dutyId","custId");
				 var datas=new Array(ownPostIds[i],id);
					if (IsNotEmpty(datas)){
						addToParser(heads, datas, "del" , parser3);
						jsonParserStr3 =  JSON.stringify(parser3);
					}	
			}
			
		}
				
		$("#close_this").attr("disabled",true);			
	 $.post("../user/edit/updateInfo",{"data":jsonParserStr,"shopList":jsonParserStr2,"postDate":jsonParserStr3,"html":editorHtml}, function(data) {
			$("#close_this").attr("disabled",false);			
			var dt = JSON.parse(data);
			if(IsEmpty(dt)){
				art.dialog({fixed:true, lock: true,content:"修改出错",icon:'error',ok:true});	
				return false;
				}
				if(dt.state==0){
					upload(id);
					 }else if(dt.state==1){
					art.dialog({fixed:true, lock: true,content:dt.msg,icon:'error',ok:true});	
				}else{
					checkStateShowErrorMsgAndDealResult(data);
				}	
			
		});
 }
 
 function upload(id){
	 if(IsEmpty($("#upload").val())){
		 $("#window_change").hide();
			$("#yinying1").hide();
			InitTable();
		art.dialog({fixed:false, lock: true,content:"操作成功",icon:'succeed',ok:true});
		 return false
	 }
		$.ajaxFileUpload({
			url :"../user/upload/image/"+id, 
			secureuri : false,
			fileElementId : 'upload',
			dataType : 'json',
			success : function(data){
				if(IsEmpty(data)){
					art.dialog({fixed:false, lock: true,content:"上传图片出错",icon:'error',ok:true});
					return false;
					}
					if(data.state==0){
						
						art.dialog({fixed:false, lock: true,content:"操作成功",icon:'succeed',ok:true});
						 $("#window_change").hide();
							$("#yinying1").hide();
							InitTable();
							browse('upload','imgSrc',100,100);

					}else if(data.state==1){
						art.dialog({fixed:false, lock: true,content:"保存图片出错,请重新上传图片",icon:'error',ok:true});	
					}else{
						checkStateShowErrorMsgAndDealResult(data);
					}
					
			},
			error : function(data) {
				art.dialog({fixed:true, lock: true,content:'上传图片失败',icon:'error',ok:true});	
				return false;
			}
		});
	}
 
 function resetForm(){
$("#close_this").attr("disabled",false);			
 $("#form input").val("");
 }
</script>
<style type="text/css">
table.member_list th, table.member_list td {
	padding: 4px 1px;
}
</style>
</head>

<body>
<div id="yinying"></div>
<div id="yinyingCenter"></div>
<div id="yinying1"></div>
<!-- InstanceBeginEditable name="EditRegion3" -->
<form id="valiForm" >
  <div id="window_change" class="member_search hideDiv" style="width:520px;">
    <div class="closeTop"><span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span></div>
    <input type="hidden" id="doflag">
    <input type="hidden" id="shopflag">
    <input type="hidden" id="defaultCflag">
    <input type="hidden" id="updateId">
    <p>
      <label><span> 店面：</span>
        
        <select id="shopName2" style=";height:20px;">
        </select>
      </label>
   </p>
   <p>
      <label><span>姓名：</span>
        <input type="text" id="Name"><!-- <br> <span id="NameTip" style="display:none;"></span> --> 
      </label>
    </p>
    <p>
<span>人员照片：</span>
<input id="imageUrl" class="isDisabled" type="text">
<input class="btn" type="button" value="...">
<input id="upload" class="file isDisabled" type="file" name="upload">
<span id="imgSrc" class="onlyImgSrc"><img src="../images/img_activities1.jpg"></span>
</p>
    <p>
      <label><span>登录名：</span>
        <input type="text" id="LoginName2"><!-- <br><span id="LoginName2Tip"></span>  -->
      </label>
   
      <label><span>密码：</span>
       	<input type="password" id="password"><!-- <br><span id="passwordTip"></span> -->
      </label>
      </p>
      <p>
      <label>
      	<span>性别：</span>
        <select id="Sex">
          <option value="1">男</option>
          <option value="0">女</option>
        </select>
      </label>
  		<label><span>状态：</span>
        <select id="Status2">
          <option value="0">正常</option>
          <option value="1">非正常</option>
        </select>
      </label>
     
    </p>
    <p>
      <label><span>身份证：</span>
        <input type="text" id="IDNumber"> <!-- <br><span id="IDNumberTip"></span> -->
      </label>
   
      <label><span>电话：</span>
        <input type="text" id="Tel"><br><!-- <span id="TelTip"></span> -->
      </label>
    </p>
     
    <p>
      <label><span>手机：</span>
        <input type="text" id="Mp"><!-- <br><span id="MpTip"></span> -->
      </label>
 
      <label><span>Email：</span>
        <input type="text" id="Email"><!-- <br><span id="EmailTip"></span> -->
      </label>
    </p>
    <p>
      <label><span>邮编：</span>
        <input type="text" id="ZipCode"><!-- <br><span id="ZipCodeTip" class=''></span> -->
      </label>
      <label><span>岗位：</span>
        <input type="text" id="onlyPost" readonly  >
      </label>
    </p>
     <p>
      <label><span>地址：</span>
        <input type="text" id="Address">
      </label>
      
        <input type="checkbox" id="isHost" style="width: 20px;">主持人
    </p>
    <p>
    <label><span>个人首页： </span>
    <input type = "text" id="indexUrl" style="width: 250px;" >
    <input type="button" class="btn" id="editIndex_btn" value="管理首页" >
      </label>
    </p>  
    <div class="submit_btn">
      <input type="button" value="保存信息" class="common_btn" id="close_this" onclick="save()">
    </div>
  </div>
</form>
<div id="Postset" class="hideDiv">
<div class="closeTop"><span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span></div>
  <table id="postList" width="100%" cellspacing="1" cellpadding="0" border="0" id="postList" class="member_list">
    	<caption>岗位列表    </caption>
    	<thead>
    	<tr>
        	<th>店铺名称</th>
        	<th>岗位编号</th>
        	<th>岗位名称</th>
        	<th>操作</th>
        </tr>
        </thead>
        <tbody>
        	
        </tbody>
    </table>
    
</div>
<div id="personShop" class="hideDiv">
    <div class="closeTop"><span onclick="saveOwnShopIds()" class="closeThe"><img src="../images/close.png"></span></div>
      <table id="ownShopList" class="member_list" cellpadding="4" cellspacing="0" border="1" width="100%">
      <caption><strong>店铺列表</strong><input type="button" value="增加" class="common_btn" onclick="showShopList('2')"></caption>
        <thead>
          <tr>
            <th>店面序号</th>
            <th>店面名称</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>
        	
        </tbody>
      </table>
      <div class="submit_btn">
	<input id="close_this" class="common_btn" type="button" value="保存信息" onclick="saveOwnShopIds();">
</div>
</div>
<div id="personPost" class="hideDiv">
    <div class="closeTop"><span onclick="saveOwnPostIds()" class="closeThe"><img src="../images/close.png"></span></div>
      <table id="ownPostList" class="member_list" cellpadding="4" cellspacing="0" border="1" width="100%">
      <caption><strong>岗位列表</strong><input type="button" value="增加" class="common_btn"  onclick="showPost();"></caption>
        <thead>
          <tr>
            <th>店铺名称</th>
            <th>岗位编号</th>
            <th>岗位名称</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>
        	
        </tbody>
      </table><div class="submit_btn">
	<input id="close_this" class="common_btn" type="button" value="保存信息" onclick="saveOwnPostIds();">
</div>
</div>
<div id="shopShow" class="hideDiv">
  <div style="float:right;margin-bottom:5px;width:20px;height:20px;line-height:20px;text-align:center;background-color:#eee;margin-bottom:5px;border:1px solid #ccc;" > <span style="cursor: pointer;font-size: 14px;" onclick="closeShopShow();" >X</span> </div>
  <div class="bottom_search">
    <div class="serWrapper"><input type="text" id="searchName" class="txt"><strong class="refresh" onclick="$('#searchName').val('')">清空</strong></div>
    <input type="button" style="width:auto;margin-left:5px;" value="查询" onclick="search2()" class="common_btn">
  </div>
  <table   id="shopList" cellpadding="4" cellspacing="0" border="1" width="100%">
    <thead>
      <tr>
        <th>店面ID</th>
        <th>店面名称</th>
        <th>电话</th>
        <th>操作</th>
      </tr>
    </thead>
  </table>
  <div id="shopPager"></div>
</div>
<div class="container" id="container">
  <div class="container_R fr">
    <div class="place">人员设置</div>
    <div class="member_search">
      <p><span>
        <input type="checkbox" id="shopIsChoosed" style="width:auto;height:auto;border:none;">
        店面：</span>
        <select id="shopName" disabled="disabled" onclick="showShopList(1)" style="height:20px;">
        </select>
        <span>姓名：</span>
        <input type="text" id="username" value="" class="absoluteTxt">
        <span>登录名：</span>
        <input type="text" id="loginname" value="" class="absoluteTxt">
        </p>
        <p>
        <span>手机号：</span>
        <input type="text" id="phone" class="absoluteTxt">  
      <span>状态：</span>
      <select id="status">
        <option value="">所有</option>
        <option value="0">正常</option>
        <option value="1">非正常</option>
      </select>
      <input type="button" value="查询" class="btn" onclick="search()">
      </p>
    </div>
    <table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="memberList">
      <caption>
      <strong>人员列表 <span id="sup">共0条</span></strong> <a href="javascript:void(0)" onclick="downRescouse()">导出数据</a> <input type="button" value="增加人员"  onclick='showAddPersonnel()' class="common_btn addList">
      </caption>
      <thead>
        <tr>
        	<th >图片 </th>
          <th>姓名</th>
          <th >登录名</th>
          <th>性别</th>
          <th >身份证</th>
          <th >地址</th>
          <th >电话</th>
          <th>手机</th>
          <th >Email</th>
          <th>岗位</th>
          <th >状态</th>
          <th >建档时间</th>
          <th >操作</th>
        </tr>
      </thead>
      <tbody>
       
      </tbody>
    </table>
     <div id="NoResult"  class="Nothing" style="text-align:center;display: none;">无符合条件的数据！</div>
    <div id="pager" style="float: right;"></div>
  </div>
  <div class="fc"></div>
</div>
<!-- InstanceEndEditable --> 
<script type="text/javascript" src="../js/header.js"></script> 
<script type="text/javascript" src="../js/left.js"></script> 
<script type="text/javascript" src="../js/footer.js"></script> 
<script type="text/javascript">
clearThis("absoluteTxt");
showTab(1,3);
</script>
</body>
<!-- InstanceEnd -->
</html>
